/******************************************************************************
 * Author:      671643387
 * Created:     2016/9/27
 *****************************************************************************/

var fs = require('fs');

exports.login = function(player, query, resp, onHandled) {
    var user = player.user;

    var name = query.args.name;
    var headpic = query.args.headIcon;
    var sex = query.args.sex;

    user.info.name = name;
    user.info.headpic = headpic;
    user.info.sex = sex;
    //player.markDirty('info.name');
    //player.markDirty('info.headpic');
    //player.save();

    var infoJson = getInfoJson();

    resp.data = {
        info: {
            name: user.info.name,
            headpic: user.info.headpic,
            sex: sex,
        },
        status: {
            card: user.status.card,
        },
        marks: {
            room: user.marks.room,
        },
        reports: user.reports,
        notice: infoJson["notice"] || "",
        chargeContacts: infoJson["charge"] || "",
    };
    onHandled();
};

var infoJson = null;
function getInfoJson() {
    if (!infoJson) {
        try {
            infoJson = JSON.parse(fs.readFileSync('info.json', 'utf8'));
        } catch (e) {
            ERROR(e);
        }
    }
    return infoJson;
}